<?php 
class DomArParserTestCase extends DomArTestUnitTestCase {

	public function testParser() {
	
		$class = DomArClassParser::get('DomArParserTest');

		
		$this->assertEqual( $class->name, 'DomArParserTest');
		$this->assertEqual( $class->tableName, 'domarparsertest');
	
		$this->assertEqual( count($class->properties), 1 );
		$this->assertEqual( count($class->recordProperties), 5 );
		$this->assertEqual( count($class->methods), 3 );
		$this->assertEqual( count($class->recordMethods), 1 );
		
		$this->assertEqual( get_class($class->constructor), 'DomArClassParserMethod' );
		
		$this->assertEqual( count($class->classListeners), 1 );
		$this->assertEqual( count($class->propertyListeners), 1 );
		

		$this->assertEqual( count($class->propertyListeners['number']), 1 );
		$this->assertEqual( $class->propertyListeners['number']['beforeupdate'][0]->method, 'beforeSaveB' );
		$this->assertEqual( $class->propertyListeners['number']['beforeupdate'][0]->propertyName, 'number' );

		$this->assertEqual( $class->indexes, array(array('type'=>'index','columns' => array('number','number2')),array('type'=>'unique','columns' => array('number','number3'))));
		
		
		// Test properties.
		$property = $class->properties['justProperty'];
		$this->assertEqual( get_class($property), 'DomArClassParserProperty' );
		$this->assertEqual( $property->name, 'justProperty' );
		$this->assertEqual( $property->className, 'DomArParserTest' );
		$this->assertEqual( $property->code, 'public $justProperty = 0;' );
		
		
		$property = $class->recordProperties['name'];
		$this->assertEqual( get_class($property), 'DomArClassParserRecordProperty_Field' );
		$this->assertEqual( $property->type, 'text' );
		$this->assertEqual( $property->param1, NULL );
		$this->assertEqual( $property->param2, NULL );
		$this->assertEqual( $property->index, NULL );
		$this->assertEqual( $property->name, 'name' );
		$this->assertEqual( $property->className, 'DomArParserTest' );
		$this->assertEqual( $property->code, 'private $name;' );
		$this->assertEqual( $property->handlerClassName, NULL );
		$this->assertEqual( $property->createHandlerCode, NULL );
		
		$class->check();
		
		$this->assertEqual( $property->handlerClassName, 'DomArProperty_Text' );
		$this->assertEqual( $property->createHandlerCode, "new DomArProperty_Text('name',true,true,'')" );
	}
	
	public function testClassIndexes() {
		DomArParserTest::getTable()->update();
		$table = DomArParserTest::getTable();
		$index = $table->getIndexes();
		$this->assertIdentical($index[3], array('name' => 'ci_number_number2', 'type' => 'index'));
		$this->assertIdentical($index[1], array('name' => 'ci_number_number3', 'type' => 'unique'));
	}

	public function testClassProperties() {
		
		DomArParserClassPropertiesExtend::getTable()->update();
		
		$a = new DomArParserClassPropertiesExtend();
		
		$contents = file_get_contents( Dom::getClassPath('DomArParserClassProperties') );
		$this->assertTrue( strpos( $contents, 'abstract class DomArParserClassProperties extends DomArParserClassPropertiesRecord implements IDomArParserClassProperties'));
		$this->assertTrue( strpos( $contents, 'public $property;'));
		$this->assertTrue( strpos( $contents, 'public static $staticProperty;'));
		$this->assertTrue( strpos( $contents, 'public function method()'));
		$this->assertTrue( strpos( $contents, 'public static function staticMethod'));
		$this->assertTrue( strpos( $contents, 'abstract public function abstractMethod();'));
		$this->assertTrue( strpos( $contents, 'abstract public static function abstractStaticMethod();'));
		$this->assertTrue( strpos( $contents, 'const a = 10;'));
		
		$contents = file_get_contents( Dom::getClassPath('DomArParserClassPropertiesExtend') );
		$this->assertTrue( strpos( $contents, 'public function interfaceMethod()'));
		$this->assertTrue( strpos( $contents, 'class DomArParserClassPropertiesExtend extends DomArParserClassPropertiesExtendRecord implements IDomArParserClassProperties,IDomArParserClassProperties2'));
		$this->assertTrue( strpos( $contents, 'public function abstractMethod() {}'));
		$this->assertTrue( strpos( $contents, 'public static function abstractStaticMethod() {}'));
		$this->assertTrue( strpos( $contents, 'const b = 20;'));
	}
}
?>